/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */
import java.util.*;

public class Registries {
    
    public static Hashtable<String, Registry> reg_table = new Hashtable<String, Registry>();
    public static Registry reg0,reg1,reg2,reg3,reg4,reg5,reg6,reg7;
    public static Hashtable<Integer, ArrayList<Integer>> reg_stack = new Hashtable();
    private static ArrayList<Integer> reg_list = new ArrayList<Integer>(8);

    public Registries(){

        reg0 = new Registry("R0", 0);
        reg1 = new Registry("R1", 0);
        reg2 = new Registry("R2", 0);
        reg3 = new Registry("R3", 0);
        reg4 = new Registry("R4", 0);
        reg5 = new Registry("R5", 0);
        reg6 = new Registry("R6", 0);
        reg7 = new Registry("R7", 0);

        reg_table.put("R0", reg0);
        reg_table.put("R1", reg1);
        reg_table.put("R2", reg2);
        reg_table.put("R3", reg3);
        reg_table.put("R4", reg4);
        reg_table.put("R5", reg5);
        reg_table.put("R6", reg6);
        reg_table.put("R7", reg7);

        reg_list.add(0);
        reg_list.add(0);
        reg_list.add(0);
        reg_list.add(0);
        reg_list.add(0);
        reg_list.add(0);
        reg_list.add(0);
        reg_list.add(0);
    }

    public static void pushRegistries(Integer pid){
        
        reg_list.set(0, reg_table.get("R0").getValue());
        reg_list.set(1, reg_table.get("R1").getValue());
        reg_list.set(2, reg_table.get("R2").getValue());
        reg_list.set(3, reg_table.get("R3").getValue());
        reg_list.set(4, reg_table.get("R4").getValue());
        reg_list.set(5, reg_table.get("R5").getValue());
        reg_list.set(6, reg_table.get("R6").getValue());
        reg_list.set(7, reg_table.get("R7").getValue());

        reg_table.get("R0").setValue(0);
        reg_table.get("R1").setValue(0);
        reg_table.get("R2").setValue(0);
        reg_table.get("R3").setValue(0);
        reg_table.get("R4").setValue(0);
        reg_table.get("R5").setValue(0);
        reg_table.get("R6").setValue(0);
        reg_table.get("R7").setValue(0);

        reg_stack.put(pid, new ArrayList(reg_list));
    }

    public static void popRegistries(Integer pid){
        ArrayList<Integer> reg_list_temp = reg_stack.get(pid);
        reg_stack.remove(pid);
        
        reg_table.get("R0").setValue(reg_list_temp.get(0));
        reg_table.get("R1").setValue(reg_list_temp.get(1));
        reg_table.get("R2").setValue(reg_list_temp.get(2));
        reg_table.get("R3").setValue(reg_list_temp.get(3));
        reg_table.get("R4").setValue(reg_list_temp.get(4));
        reg_table.get("R5").setValue(reg_list_temp.get(5));
        reg_table.get("R6").setValue(reg_list_temp.get(6));
        reg_table.get("R7").setValue(reg_list_temp.get(7));
    }
}
